#!/usr/bin/python3
# coding: utf-8
# file: shutil_.py
# 2018-06-12
import shutil, os


def clear_tree(tar_dir):
	''' Python3 清空文件夹 '''

	for root, dirs, files in os.walk(tar_dir):
		for tree in dirs:
			tree = os.path.join(root, tree)
			try:
				shutil.rmtree(tree)
				print('删除临时文件夹 {tree} 成功'.format(tree=tree))
			except WindowsError as e:
				print(e)
		for file in files:
			file = os.path.join(root, file)
			try:
				os.remove(file)
				print('删除临时文件 {file} 成功'.format(file=file))
			except WindowsError as e:
				print(e)



if __name__ == '__main__':
	tar_dir = os.environ.get('TEMP')
	clear_tree(tar_dir)
	